/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Francisco
 */
@Entity
@Table(name = "consumidor")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Consumidor.findAll", query = "SELECT c FROM Consumidor c"),
    @NamedQuery(name = "Consumidor.findByIdConsumidor", query = "SELECT c FROM Consumidor c WHERE c.idConsumidor = :idConsumidor"),
    @NamedQuery(name = "Consumidor.findByNombre", query = "SELECT c FROM Consumidor c WHERE c.nombre = :nombre"),
    @NamedQuery(name = "Consumidor.findByDescripcion", query = "SELECT c FROM Consumidor c WHERE c.descripcion = :descripcion"),
    @NamedQuery(name = "Consumidor.findByFechaCaptura", query = "SELECT c FROM Consumidor c WHERE c.fechaCaptura = :fechaCaptura"),
    @NamedQuery(name = "Consumidor.findByTipo", query = "SELECT c FROM Consumidor c WHERE c.tipo = :tipo"),
    @NamedQuery(name = "Consumidor.findByEstatus", query = "SELECT c FROM Consumidor c WHERE c.estatus = :estatus")})
@Inheritance(strategy= InheritanceType.JOINED)
@DiscriminatorColumn(name="tipo", discriminatorType= DiscriminatorType.STRING)
public class Consumidor implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_consumidor")
    private Integer idConsumidor;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "nombre")
    private String nombre;
    @Size(max = 200)
    @Column(name = "descripcion")
    private String descripcion;
    @Basic(optional = false)
    @NotNull
    @Column(name = "fecha_captura")
    @Temporal(TemporalType.DATE)
    private Date fechaCaptura;
    @Size(max = 20)
    @Column(name = "tipo")
    private String tipo;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 1)
    @Column(name = "estatus")
    private String estatus;
    @JoinTable(name = "reporte_consumidor", joinColumns = {
        @JoinColumn(name = "id_consumidor", referencedColumnName = "id_consumidor")}, inverseJoinColumns = {
        @JoinColumn(name = "id_reporte", referencedColumnName = "id_reporte")})
    @ManyToMany
    private List<Reporte> reporteList;
    @ManyToMany(mappedBy = "consumidorList")
    private List<Categoria> categoriaList;
    @JoinColumn(name = "id_usuario", referencedColumnName = "id_usuario")
    @ManyToOne(optional = false)
    private Usuario idUsuario;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idConsumidor")
    private List<Ingreso> ingresoList;
    @OneToMany(mappedBy = "idConsumidor")
    private List<Usuario> usuarioList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idConsumidor")
    private List<LigaUsuarioConsumidor> ligaUsuarioConsumidorList;

    public Consumidor() {
    }

    public Consumidor(Integer idConsumidor) {
        this.idConsumidor = idConsumidor;
    }

    public Consumidor(Integer idConsumidor, String nombre, Date fechaCaptura, String estatus) {
        this.idConsumidor = idConsumidor;
        this.nombre = nombre;
        this.fechaCaptura = fechaCaptura;
        this.estatus = estatus;
    }

    public Integer getIdConsumidor() {
        return idConsumidor;
    }

    public void setIdConsumidor(Integer idConsumidor) {
        this.idConsumidor = idConsumidor;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Date getFechaCaptura() {
        return fechaCaptura;
    }

    public void setFechaCaptura(Date fechaCaptura) {
        this.fechaCaptura = fechaCaptura;
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public String getEstatus() {
        return estatus;
    }

    public void setEstatus(String estatus) {
        this.estatus = estatus;
    }

    @XmlTransient
    public List<Reporte> getReporteList() {
        return reporteList;
    }

    public void setReporteList(List<Reporte> reporteList) {
        this.reporteList = reporteList;
    }

    @XmlTransient
    public List<Categoria> getCategoriaList() {
        return categoriaList;
    }

    public void setCategoriaList(List<Categoria> categoriaList) {
        this.categoriaList = categoriaList;
    }

    public Usuario getIdUsuario() {
        return idUsuario;
    }

    public void setIdUsuario(Usuario idUsuario) {
        this.idUsuario = idUsuario;
    }

    @XmlTransient
    public List<Ingreso> getIngresoList() {
        return ingresoList;
    }

    public void setIngresoList(List<Ingreso> ingresoList) {
        this.ingresoList = ingresoList;
    }

    @XmlTransient
    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }

    @XmlTransient
    public List<LigaUsuarioConsumidor> getLigaUsuarioConsumidorList() {
        return ligaUsuarioConsumidorList;
    }

    public void setLigaUsuarioConsumidorList(List<LigaUsuarioConsumidor> ligaUsuarioConsumidorList) {
        this.ligaUsuarioConsumidorList = ligaUsuarioConsumidorList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idConsumidor != null ? idConsumidor.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Consumidor)) {
            return false;
        }
        Consumidor other = (Consumidor) object;
        if ((this.idConsumidor == null && other.idConsumidor != null) || (this.idConsumidor != null && !this.idConsumidor.equals(other.idConsumidor))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Consumidor[ idConsumidor=" + idConsumidor + " ]";
    }
    
}
